package org.yray.netty;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * 初始化配置器，channel注册成功后，会执行里面相应的初始化方法
 * @author asus
 *
 */
public class HelloServerInitializer extends ChannelInitializer<SocketChannel>{

    @Override
    protected void initChannel(SocketChannel channel) throws Exception {

        //channel获取相应的管道
        ChannelPipeline pipeline = channel.pipeline();

        //为管道增加相应的handler，可理解为是拦截器，或者监听器，监听客户端建立连接后的信息
        //当请求到服务端，我们需要对写出到客户端的数据做编码处理
        pipeline.addLast("httpCode",new HttpServerCodec());

        //添加自定义助手类，可添加多个
        pipeline.addLast("myHandler",new MyHandler());

    }

}


